

<!doctype html>

<html lang="en" data-content_root="../../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>skidl.interface &#8212; SKiDL 2.2.0 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
    <link rel="stylesheet" type="text/css" href="../../_static/bizstyle.css?v=a66e137f" />
    
    <script src="../../_static/documentation_options.js?v=b21de401"></script>
    <script src="../../_static/doctools.js?v=9bcbadda"></script>
    <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../../_static/bizstyle.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <!--[if lt IE 9]>
    <script src="_static/css3-mediaqueries.js"></script>
    <![endif]-->
  </head><body>
    <h1 id="site-title"><a href="../../../../"><img src="../../../../images/slim_banner.png" width="100%"></a></h1>
    
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SKiDL 2.2.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">skidl.interface</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for skidl.interface</h1><div class="highlight"><pre>
<span></span><span class="c1"># -*- coding: utf-8 -*-</span>

<span class="c1"># The MIT License (MIT) - Copyright (c) Dave Vandenbout.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Interface management in SKiDL.</span>

<span class="sd">This module provides the Interface class, which bundles nets, buses, and pins into</span>
<span class="sd">a single entity that can be used for connecting subsystems with complex I/O.</span>
<span class="sd">Interfaces make it easier to handle groups of related signals and enable </span>
<span class="sd">connecting subsystems with matching interfaces using simple operators.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">.alias</span> <span class="kn">import</span> <span class="n">Alias</span>
<span class="kn">from</span> <span class="nn">.bus</span> <span class="kn">import</span> <span class="n">Bus</span>
<span class="kn">from</span> <span class="nn">.net</span> <span class="kn">import</span> <span class="n">Net</span>
<span class="kn">from</span> <span class="nn">.netpinlist</span> <span class="kn">import</span> <span class="n">NetPinList</span>
<span class="kn">from</span> <span class="nn">.pin</span> <span class="kn">import</span> <span class="n">Pin</span>
<span class="kn">from</span> <span class="nn">.skidlbaseobj</span> <span class="kn">import</span> <span class="n">SkidlBaseObject</span>
<span class="kn">from</span> <span class="nn">.utilities</span> <span class="kn">import</span> <span class="p">(</span>
    <span class="n">expand_indices</span><span class="p">,</span>
    <span class="n">export_to_all</span><span class="p">,</span>
    <span class="n">filter_list</span><span class="p">,</span>
    <span class="n">from_iadd</span><span class="p">,</span>
    <span class="n">list_or_scalar</span><span class="p">,</span>
    <span class="n">rmv_iadd</span><span class="p">,</span>
    <span class="n">set_iadd</span><span class="p">,</span>
<span class="p">)</span>



<div class="viewcode-block" id="Interface">
<a class="viewcode-back" href="../../rst_output/skidl.interface.html#skidl.interface.Interface">[docs]</a>
<span class="nd">@export_to_all</span>
<span class="k">class</span> <span class="nc">Interface</span><span class="p">(</span><span class="nb">dict</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A bundle of nets, buses, and pins that can be accessed as attributes or dict entries.</span>
<span class="sd">    </span>
<span class="sd">    An Interface groups related nets, buses, and pins into a single entity where each</span>
<span class="sd">    item can be accessed either as an attribute (obj.item) or as a dictionary key (obj[&#39;item&#39;]).</span>
<span class="sd">    This makes Interfaces useful for standardizing connections between subsystems or</span>
<span class="sd">    for creating reusable connection patterns.</span>
<span class="sd">    </span>
<span class="sd">    Args:</span>
<span class="sd">        *args: Positional arguments passed to dict constructor.</span>
<span class="sd">        **kwargs: Keyword arguments defining nets/buses to include in the interface.</span>
<span class="sd">        </span>
<span class="sd">    Keyword Args:</span>
<span class="sd">        unbundle (bool, optional): Whether to automatically unbundle buses into individual</span>
<span class="sd">            nets that can be accessed directly. Defaults to True.</span>
<span class="sd">            </span>
<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; power = Interface(vcc=Net(&#39;VCC&#39;), gnd=Net(&#39;GND&#39;))</span>
<span class="sd">        &gt;&gt;&gt; power.vcc += part1[&#39;VCC&#39;]  # Connect using attribute access</span>
<span class="sd">        &gt;&gt;&gt; power[&#39;gnd&#39;] += part1[&#39;GND&#39;]  # Connect using dictionary access</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># Set the default ERC functions for all Interface instances.</span>
    <span class="n">erc_list</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>

        <span class="c1"># By default, buses are unbundled into individual nets.</span>
        <span class="n">unbundle</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;unbundle&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">unexpio</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>

        <span class="c1"># Start with a standard dictionary of objects.</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__setattr__</span><span class="p">(</span><span class="s2">&quot;match_pin_regex&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">()):</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="p">(</span><span class="n">Pin</span><span class="p">,</span> <span class="n">Net</span><span class="p">,</span> <span class="n">Bus</span><span class="p">,</span> <span class="n">NetPinList</span><span class="p">,</span> <span class="n">SkidlBaseObject</span><span class="p">)):</span>
                <span class="c1"># Add SKiDL-type objects.</span>
                <span class="bp">self</span><span class="o">.</span><span class="fm">__setattr__</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">unbundle</span><span class="o">=</span><span class="n">unbundle</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># Add standard Python objects.</span>
                <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__setattr__</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__setattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">unbundle</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set an attribute and corresponding dict entry in the interface.</span>
<span class="sd">        </span>
<span class="sd">        This method handles creating net-like objects for pin-like inputs,</span>
<span class="sd">        setting up aliases for the keys, and optionally unbundling buses</span>
<span class="sd">        into individual nets.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            key (str): Name for the attribute/dict entry.</span>
<span class="sd">            value: The value to associate with the key.</span>
<span class="sd">            unbundle (bool, optional): Whether to unbundle buses. Defaults to True.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># Create net-like objects for pin-like objects.</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">NetPinList</span><span class="p">):</span>
            <span class="c1"># Convert NetPinList into a Bus.</span>
            <span class="n">value</span> <span class="o">=</span> <span class="n">Bus</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Pin</span><span class="p">):</span>
            <span class="c1"># Convert Pin into a Net.</span>
            <span class="n">n</span> <span class="o">=</span> <span class="n">Net</span><span class="p">()</span>
            <span class="n">n</span> <span class="o">+=</span> <span class="n">value</span>
            <span class="n">value</span> <span class="o">=</span> <span class="n">n</span>

        <span class="c1"># Assign the key as an alias to any net-like object.</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="p">(</span><span class="n">Net</span><span class="p">,</span> <span class="n">Bus</span><span class="p">)):</span>
            <span class="n">value</span><span class="o">.</span><span class="n">aliases</span> <span class="o">+=</span> <span class="n">key</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">unexpio</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

        <span class="c1"># Add the value to the dictionary and as an attribute.</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">SkidlBaseObject</span><span class="p">):</span>
            <span class="c1"># Only SKiDL-type objects get added as dictionary items.</span>
            <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__setitem__</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__setattr__</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>

        <span class="c1"># If enabled, expand a bus and add its individual nets.</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">Bus</span><span class="p">)</span> <span class="ow">and</span> <span class="n">unbundle</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
                <span class="n">n</span> <span class="o">=</span> <span class="n">Net</span><span class="p">(</span><span class="n">circuit</span><span class="o">=</span><span class="n">v</span><span class="o">.</span><span class="n">circuit</span><span class="p">)</span>
                <span class="n">n</span><span class="o">.</span><span class="n">aliases</span> <span class="o">+=</span> <span class="n">key</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
                <span class="n">n</span> <span class="o">+=</span> <span class="n">v</span>
                <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__setitem__</span><span class="p">(</span><span class="n">key</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">),</span> <span class="n">n</span><span class="p">)</span>
                <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__setattr__</span><span class="p">(</span><span class="n">key</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">),</span> <span class="n">n</span><span class="p">)</span>
                <span class="c1"># self.setattr(self, key + str(i), n)</span>

    <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">io_ids</span><span class="p">,</span> <span class="o">**</span><span class="n">criteria</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get interface items by name, regex, or other criteria.</span>
<span class="sd">        </span>
<span class="sd">        This method allows retrieving individual items or groups of items</span>
<span class="sd">        from the interface based on names, regular expressions, or other</span>
<span class="sd">        attribute criteria.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            io_ids: Names or patterns of interface items to retrieve.</span>
<span class="sd">                If empty, all items may be retrieved.</span>
<span class="sd">                </span>
<span class="sd">        Keyword Args:</span>
<span class="sd">            match_regex (bool, optional): Whether to use regex matching. Default is False.</span>
<span class="sd">            criteria: Attribute values that items must match to be retrieved.</span>
<span class="sd">            </span>
<span class="sd">        Returns:</span>
<span class="sd">            Net, Pin, Bus, NetPinList, or None: The selected item(s) or None if no match.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># Extract permission to search for regex matches in pin names/aliases.</span>
        <span class="n">match_regex</span> <span class="o">=</span> <span class="n">criteria</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;match_regex&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">match_pin_regex</span>

        <span class="c1"># If no pin identifiers were given, then use a wildcard that will</span>
        <span class="c1"># select all pins.</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">io_ids</span><span class="p">:</span>
            <span class="n">io_ids</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;.*&quot;</span><span class="p">]</span>
            <span class="n">match_regex</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="c1"># An interface doesn&#39;t have pins, so set pin slice bounds to zero.</span>
        <span class="n">min_pin</span><span class="p">,</span> <span class="n">max_pin</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>

        <span class="c1"># Get I/O entries.</span>
        <span class="n">io_types</span> <span class="o">=</span> <span class="p">(</span><span class="n">Net</span><span class="p">,</span> <span class="n">Pin</span><span class="p">,</span> <span class="n">NetPinList</span><span class="p">,</span> <span class="n">Bus</span><span class="p">)</span>
        <span class="n">ios</span> <span class="o">=</span> <span class="p">[</span><span class="n">io</span> <span class="k">for</span> <span class="n">io</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">values</span><span class="p">()</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">io</span><span class="p">,</span> <span class="n">io_types</span><span class="p">)]</span>

        <span class="c1"># Use this for looking up the dict key using the id of a given I/O.</span>
        <span class="n">id_to_key</span> <span class="o">=</span> <span class="p">{</span><span class="nb">id</span><span class="p">(</span><span class="n">v</span><span class="p">):</span> <span class="n">k</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>

        <span class="c1"># Go through the I/O entries and find the ones selected by the IDs.</span>
        <span class="n">selected_ios</span> <span class="o">=</span> <span class="n">NetPinList</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">io_id</span> <span class="ow">in</span> <span class="n">expand_indices</span><span class="p">(</span><span class="n">min_pin</span><span class="p">,</span> <span class="n">max_pin</span><span class="p">,</span> <span class="n">match_regex</span><span class="p">,</span> <span class="o">*</span><span class="n">io_ids</span><span class="p">):</span>

            <span class="c1"># Look for an exact match of the I/O key name with the current ID.</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">io</span> <span class="o">=</span> <span class="nb">dict</span><span class="o">.</span><span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">io_id</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="c1"># No exact match on I/O key name, so keep looking below.</span>
                <span class="k">pass</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># Add exact match to the list of selected I/Os and go to the next ID.</span>
                <span class="n">selected_ios</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">io</span><span class="p">)</span>
                <span class="k">continue</span>

            <span class="c1"># Check I/O aliases for an exact match with the current ID.</span>
            <span class="n">tmp_ios</span> <span class="o">=</span> <span class="n">filter_list</span><span class="p">(</span><span class="n">ios</span><span class="p">,</span> <span class="n">aliases</span><span class="o">=</span><span class="n">io_id</span><span class="p">,</span> <span class="n">do_str_match</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">criteria</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">io</span> <span class="ow">in</span> <span class="n">tmp_ios</span><span class="p">:</span>
                <span class="n">selected_ios</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">io</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">tmp_ios</span><span class="p">:</span>
                <span class="c1"># Found exact match between alias and ID, so done with this ID and go to next ID.</span>
                <span class="k">continue</span>

            <span class="c1"># Skip regex matching if not enabled.</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">match_regex</span><span class="p">:</span>
                <span class="k">continue</span>

            <span class="c1"># OK, ID doesn&#39;t exactly match an I/O name or alias. Does it match as a regex?</span>
            <span class="n">tmp_ios</span> <span class="o">=</span> <span class="n">filter_list</span><span class="p">(</span><span class="n">ios</span><span class="p">,</span> <span class="n">aliases</span><span class="o">=</span><span class="n">Alias</span><span class="p">(</span><span class="n">io_id</span><span class="p">),</span> <span class="o">**</span><span class="n">criteria</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">io</span> <span class="ow">in</span> <span class="n">tmp_ios</span><span class="p">:</span>
                <span class="n">selected_ios</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">io</span><span class="p">)</span>

        <span class="c1"># Return list of I/Os that were selected by the IDs.</span>
        <span class="k">return</span> <span class="n">list_or_scalar</span><span class="p">(</span><span class="n">selected_ios</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__setitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set a dictionary entry and attribute with the same name.</span>
<span class="sd">        </span>
<span class="sd">        This method handles assignments to dictionary keys, ensuring that</span>
<span class="sd">        attribute access and dictionary access remain synchronized.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            key (str): The key to assign to.</span>
<span class="sd">            value: The value to assign.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">from_iadd</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
            <span class="c1"># The += flag in the values are no longer needed.</span>
            <span class="n">rmv_iadd</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># This is for a straight assignment of value to key.</span>
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__iadd__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other_intfc</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Connect this interface to another interface using the += operator.</span>
<span class="sd">        </span>
<span class="sd">        This connects matching nets and buses between the two interfaces.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            other_intfc (Interface): The interface to connect to this one.</span>
<span class="sd">            </span>
<span class="sd">        Returns:</span>
<span class="sd">            Interface: This interface with connections to the other interface.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">other_intfc</span><span class="p">)</span>

<div class="viewcode-block" id="Interface.connect">
<a class="viewcode-back" href="../../rst_output/skidl.interface.html#skidl.interface.Interface.connect">[docs]</a>
    <span class="k">def</span> <span class="nf">connect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other_intfc</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Connect this interface to another interface.</span>
<span class="sd">        </span>
<span class="sd">        This method connects nets and buses in this interface to those</span>
<span class="sd">        with matching names in another interface.</span>
<span class="sd">        </span>
<span class="sd">        Args:</span>
<span class="sd">            other_intfc (Interface): The interface to connect to this one.</span>
<span class="sd">            </span>
<span class="sd">        Returns:</span>
<span class="sd">            Interface: This interface with connections to the other interface.</span>
<span class="sd">            </span>
<span class="sd">        Examples:</span>
<span class="sd">            &gt;&gt;&gt; intf1 = Interface(a=Net(&#39;a&#39;), b=Net(&#39;b&#39;))</span>
<span class="sd">            &gt;&gt;&gt; intf2 = Interface(a=Net(&#39;a2&#39;), b=Net(&#39;b2&#39;))</span>
<span class="sd">            &gt;&gt;&gt; intf1.connect(intf2)  # Connect matching nets</span>
<span class="sd">            &gt;&gt;&gt; # Alternative: intf1 += intf2</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># Connect the nets/buses of this interface to the nets/buses of the other interface.</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">unexpio</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="p">(</span><span class="n">Net</span><span class="p">,</span> <span class="n">Bus</span><span class="p">,</span> <span class="n">Pin</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">other_intfc</span><span class="p">:</span>
                    <span class="bp">self</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">+=</span> <span class="n">other_intfc</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>

        <span class="c1"># Set the flag to indicate this result came from the += operator.</span>
        <span class="n">set_iadd</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span></div>
</div>

</pre></div>

            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SKiDL 2.2.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">skidl.interface</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
    &#169; Copyright 2016-2025, Dave Vandenbout.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
    </div>
  </body>
</html>